import 'package:enterprise_v6_app/app/components/common/custom_text_widget.dart';
import 'package:enterprise_v6_app/app/core/core.dart';
import 'package:enterprise_v6_app/app/data/entities/application/emergency/emergency_plans_entity.dart';

/// 应急预案通用样式
class EmergencyPlanCommonWidget {
  /// 基本信息
  static Widget getBasicInformationWidget(EmergencyPlansEntity entity) {
    return Container(
      alignment: Alignment.topCenter,
      color: const Color(0xffffffff),
      padding: EdgeInsets.symmetric(horizontal: 20.w, vertical: 16.w),
      child: SingleChildScrollView(
        child: Column(
          children: [
            CustomTextWidget.getTextRowView(title: '预案名称', value: entity.emergencyPlanName),
            AppGaps.vGap16,
            CustomTextWidget.getTextRowView(title: '预案等级', value: entity.emergencyPlanLevelName),
            AppGaps.vGap16,
            CustomTextWidget.getTextRowView(title: '编制单位', value: entity.preparedBy),
            AppGaps.vGap16,
            CustomTextWidget.getTextRowView(title: '编制时间', value: entity.preparedByDate),
            AppGaps.vGap16,
            CustomTextWidget.getTextRowView(title: '编制人', value: entity.preparedByPerson),
            AppGaps.vGap16,
            CustomTextWidget.getTextRowView(title: '预案评审日期', value: entity.emergencyPlanSelection),
            AppGaps.vGap16,
            CustomTextWidget.getTextRowView(title: '初次发布日期', value: entity.initialReleaseDate),
            AppGaps.vGap16,
            CustomTextWidget.getTextRowView(title: '定期评估周期', value: entity.regularAssessName),
            AppGaps.vGap16,
            CustomTextWidget.getTextRowView(title: '预案类别', value: entity.planTypeName),
            AppGaps.vGap16,
            CustomTextWidget.getTextRowView(title: '适用事故类型', value: entity.probationAccidentNames),
            AppGaps.vGap16,
            CustomTextWidget.getTextRowView(title: '风险是否告知周边单位', value: entity.riskReportPeripheryUnit == 1 ? '是' : '否'),
            AppGaps.vGap16,
            Visibility(
                visible: entity.riskReportPeripheryUnit == 1,
                child: Column(
                  children: [
                    CustomTextWidget.getFileRowView(title: '风险告知周边的其他单位资料', fileList: [entity.riskReportFileUrl]),
                    AppGaps.vGap16,
                  ],
                )),
            CustomTextWidget.getTextRowView(title: '是否关联重大危险源', value: entity.majorHazardAssociation == 1 ? '是' : '否'),
            AppGaps.vGap16,
            Visibility(
              visible: entity.majorHazardAssociation == 1,
              child: Column(
                children: [
                  CustomTextWidget.getTextRowView(title: '重大危险源', value: entity.majorHazardIdsName),
                  AppGaps.vGap16,
                ],
              ),
            ),
            CustomTextWidget.getTextRowView(title: '预案评审意见', value: entity.reviewComments),
            AppGaps.vGap16,
            CustomTextWidget.getFileRowView(title: '风险评估报告', fileList: [entity.riskAssessmentReport]),
            AppGaps.vGap16,
            CustomTextWidget.getFileRowView(title: '应急资源调查', fileList: [entity.emergencyResourceInvestigation]),
            AppGaps.vGap16,
            CustomTextWidget.getFileRowView(title: '预案文档', fileList: [entity.planDocument]),
          ],
        ),
      ),
    );
  }

  /// 根据状态获取状态图标
  /// 1-待发起 2-待审批 3-审批中 4-通过 5-已驳回 6-待发布 7- 已发布
  static Widget getStateView(int state) {
    String? stateText;
    Color? color;
    switch (state) {
      case 1:
        stateText = '待发起';
        color = const Color(0xFF0ED0D0);
        break;
      case 2:
        stateText = '待审批';
        color = const Color(0xFFFFA500);
        break;
      case 3:
        stateText = '审批中';
        color = const Color(0xFFB9B907);
        break;
      case 4:
        stateText = '通过';
        color = const Color(0xFF0FCE0F);
        break;
      case 5:
        stateText = '已驳回';
        color = const Color(0xFFBB0CBB);
        break;
      case 6:
        stateText = '待发布';
        color = const Color(0xFF0ED0D0);
        break;
      case 7:
        stateText = '已发布';
        color = const Color(0xFF0FCE0F);
        break;
    }
    return Container(
      alignment: Alignment.center,
      height: 18.w,
      width: 52.w,
      decoration: BoxDecoration(
        color: color ?? Colors.white,
        borderRadius: BorderRadius.only(
          topRight: Radius.circular(20.w),
          topLeft: Radius.circular(20.w),
          bottomRight: Radius.circular(20.w),
        ),
      ),
      child: Text(
        stateText ?? '',
        style: TextStyle(
          fontSize: 10.sp,
          fontWeight: FontWeight.w400,
          color: Colors.white,
        ),
      ),
    );
  }
}
